<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 header ("Content-Type:text/html; charset= utf-8");
 include_once dirname(__FILE__).'/include/conn.php';
 require_once ('config.php');
$id = $_GET['id'];
$sql = "SELECT * FROM guest_book where id = $id ";

$result = mysql_query($sql);
if(!$result) exit('查询数据错误：'.mysql_error());

$gb_array = mysql_fetch_array($result);

if($_POST){
    
	if(get_magic_quotes_gpc()){
		$reply = htmlspecialchars(trim($_POST['reply']));
	} else {
		$reply = addslashes(htmlspecialchars(trim($_POST['reply'])));
	}
	// 回复为空时，将回复时间置为空
	$replytime = $reply?time():'NULL';
	$update_sql = "UPDATE guest_book SET reply = '$reply', replytime = $replytime WHERE id = $id";
        
	if(mysql_query($update_sql)){
		exit('<script language="javascript">alert("回复成功！");self.location = "guest_book_admin.php";</script>');
	} else {
		exit('留言失败：'.mysql_error().'[ <a href="javascript:history.back()">返 回</a> ]');
	}
}
if(@$_GET['action'] == 'delete'){
	$delete_sql = "DELETE FROM guest_book WHERE id = $_GET[id]";
	if(mysql_query($delete_sql)){
		exit('<script language="javascript">alert("删除成功！");self.location = "guest_book_admin.php";</script>');
	} else {
		exit('留言失败：'.mysql_error().'[ <a href="javascript:history.back()">返 回</a> ]');
	}
}

$smarty->assign("title","留言板回复");
$smarty->assign("reply",$gb_array);//数组的不加“”
$smarty->display("guest_book_reply.html",md5("guest_book_reply.php"));

?>
